// pages/user_examine/user_examine.js
let app = getApp();


Page({

    /**
     * 页面的初始数据
     */
    data: {
        table: [],
        tttt: -1,
        lower: [],
        flge: false,
        xianshi:false
    },
    binxq(e) {
        if (e.currentTarget.dataset.lmodulename == '产量录入') {
            wx.navigateTo({
                url: '../msg_yield_details/msg_yield_details?lid=' + e.currentTarget.dataset.oid
            })
        } else if (e.currentTarget.dataset.lmodulename == '生产通知单') {
            wx.navigateTo({
                url: '../msg_notice_details/msg_notice_details?lid=' + e.currentTarget.dataset.oid
            })
        }
    },
    //待审核页面，审核通过按钮
    bindy: function (e) {
        var that = this
        console.log(e.currentTarget.dataset.oid)
        console.log(e.currentTarget.dataset.id)
        console.log(e.currentTarget.dataset.moduleno)
        console.log(e.currentTarget.dataset.lstaterun)
        wx.showModal({
            title: '提示',
            content: '确定审核通过这份订单吗',
            showCancel: true,
            cancelText: '取消',
            confirmText: '确定',
            success(res) {
                if (res.confirm) {
                    console.log('用户点击确定')
                    // 审核通过，删除订单信息
                    wx.request({
                        url: 'https://' + app.globalData.url + '/basicInfo/updateltype',
                        data: {
                            LID: e.currentTarget.dataset.oid,
                            MODULENO: e.currentTarget.dataset.moduleno,
                            LSTATERUN: e.currentTarget.dataset.lstaterun,
                            LUSERCODE: app.globalData.lusercode,
                            AUDITRECORD: ''
                        },
                        method: 'POST',
                        dataType: 'json',
                        responseType: 'text',
                        header: {
                            'content-type': 'application/x-www-form-urlencoded'
                        },
                        // 访问成功
                        success: function (res) {
                            if (res.data.success == true) {
                                wx.showToast({
                                    title: '成功',
                                    icon: 'success',
                                    duration: 2000
                                })

                                let list = that.data.table
                                list.splice(that.data.index, 1)
                                that.setData({
                                    table: list
                                })
                            } else {
                                wx.showToast({
                                    title: '失败',
                                    icon: 'none',
                                    duration: 2000
                                })
                            }

                        },
                    })
                    // that.setData({
                    //     delorder: e.currentTarget.dataset.oid
                    // })
                    // console.log('=+', that.data.delorder)
                    // var order = that.data.table
                    // var delorder = that.data.delorder
                    // for (var i = 0; i < order.length; i++) {
                    //     if (order[i].h == delorder) {
                    //         order.splice(i, 1)
                    //         i--
                    //     }
                    // }

                    //----判断是否还有待审核订单------------------------
                    if (that.data.table == '') {
                        wx.showToast({
                            title: '订单已审核完',
                            icon: 'success',
                            duration: 2000,
                            mask: 'false'
                        })
                        // setTimeout(function () {
                        //     wx.navigateBack({
                        //         delta: 1
                        //     })
                        // }, 2000)
                    }


                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })
    },


    //审核驳回按钮
    bindn(e) {
        var that = this
        wx.setStorage({
            key: 'selet',
            data: 'true',
        })
        app.globalData.selet = true
        this.dialog.showDialog();
        that.setData({
            delorder: e.currentTarget.dataset.oid
        })
        that.setData({
            // in:ind,
            oid: e.currentTarget.dataset.oid,
            moduleno: e.currentTarget.dataset.moduleno,
            lstaterun: e.currentTarget.dataset.lstaterun
        })
        console.log(that.data.in)
    },

    //驳回取消
    _cancelEvent() {
        let that = this
        console.log('你点击了取消');
        that.setData({
            etext: wx.getStorageSync('etext')
        })
        console.log('~~~~', that.data.etext)
        this.dialog.hideDialog();
    },

    //驳回确认
    _confirmEvent(e) {
        var that = this
        console.log('你点击了确定');
        this.dialog.hideDialog();
        // 获取本地缓存中的驳回理由
        // console.log(etext)
        that.setData({
            etext: wx.getStorageSync('etext')
        })
        console.log(wx.getStorageSync('etext'))
        wx.request({
            url: 'https://' + app.globalData.url + '/basicInfo/updateltypeover',
            data: {
                LID: that.data.oid,
                LMODULENO: that.data.moduleno,
                LSTATERUN: that.data.lstaterun,
                LUSERCODE: app.globalData.lusercode,
                LREASON: that.data.etext
            },
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            // 访问成功
            success: function (res) {
                if (res.data.success == true) {
                    wx.showToast({
                        title: '成功',
                        icon: 'success',
                        duration: 2000
                    })
                    //删除订单信息-------------------
                    console.log(that.data.table)
                    let list = that.data.table
                    list.splice(that.data.index, 1)
                    that.setData({
                        table: list
                    })
                    var order = that.data.order
                    var delorder = that.data.delorder
                    // for (var i = 0; i < order.length; i++) {
                    //     //console.log('12')
                    //     if (order[i].h == delorder) {
                    //         order.splice(i, 1)
                    //         i--
                    //     }
                    // }
                    that.setData({
                        table: that.data.table
                    })

                } else {
                    wx.showToast({
                        title: '失败',
                        icon: 'none',
                        duration: 2000
                    })
                }

            },
        })


        //--判断订单是否处理完--------------------------
        if (that.data.table == '') {
            wx.showToast({
                title: '订单已审核完',
                icon: 'success',
                duration: 2000,
                mask: 'false'
            })
            // setTimeout(function () {
            //     wx.navigateBack({
            //         delta: 1
            //     })
            // }, 2000)
        }
    },
    //查询跟单详情
    my_tttt(e) {
        let that = this
        let ind = e.currentTarget.dataset.index
        that.setData({
            index: e.currentTarget.dataset.index
        })
        console.log(ind)
        app.globalData.loadlid = e.currentTarget.dataset.lid
        if (that.data.flge == false) {
            //查询跟单详情接口
            that.setData({
                tttt: e.currentTarget.dataset.index,
                flge: true,
            })
        } else {
            that.setData({
                tttt: -1,
                flge: false
            })
        }
        // console.log(e.currentTarget.dataset.index)
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this
        wx.request({
            url: 'https://' + app.globalData.url + '/basicInfo/findAuditFormByCode',
            data: {
                lmobile: app.globalData.user_phone,
            },
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            header: {
                'content-type': 'application/json;charset=utf-8'
            },
            success: function (res) {
                if (res.data.status == 200) {
                    that.setData({
                        loadModal: false,
                        table: res.data.data.obj,
                        xianshi: false
                    })
                    if (res.data.data.obj == '' || res.data.data.obj == null) {
                        that.setData({
                            loadModal: false,
                            xianshi: true,
                        })
                        // wx.showModal({
                        //     title: '提示',
                        //     content: '当前数据为空',
                        //     showCancel: false,
                        //     confirmText: '确定',
                        //     success(res) {
                        //         if (res.confirm) {

                        //         }
                        //     }
                        // })
                    }
                } else {
                    that.setData({
                        xianshi: true
                    })
                    wx.showModal({
                        title: '提示',
                        content: '获取数据失败',
                        showCancel: false,
                        confirmText: '确定',
                        success(res) {
                            if (res.confirm) {

                            }
                        }
                    })
                }
            },
            fail: function (res) {
                that.setData({
                    loadModal: false,
                    xianshi: true
                })
                wx.showModal({
                    title: '提示',
                    content: '访问服务器出错',
                    showCancel: false,
                    confirmText: '确定',
                    success(res) {
                        if (res.confirm) {

                        }
                    }
                })
            },
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        this.dialog = this.selectComponent("#dialog");
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})